package cmgine.com.testqq.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.loopj.android.image.SmartImageView;

import java.util.List;

import cmgine.com.testqq.R;
import cmgine.com.testqq.bean.UserInfoWrapper;

/**
 * Created by apple on 12/25/15.
 */
public class MessageAdapter extends BaseAdapter {

    private List<UserInfoWrapper.UserInfo> infos;
    private Context context;

    public MessageAdapter(Context context, List<UserInfoWrapper.UserInfo> userInfo) {
        this.context = context;
        this.infos = userInfo;
    }

    @Override
    public int getCount() {
        return infos.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View mView;
        if (convertView != null) {
            mView = convertView;
        } else {
            mView = View.inflate(context, R.layout.message_list_item, null);
        }
        SmartImageView avatar = (SmartImageView)mView.findViewById(R.id.avatar);
        TextView nickname = (TextView)mView.findViewById(R.id.nickname);
        TextView signature = (TextView)mView.findViewById(R.id.signature);

        UserInfoWrapper.UserInfo userInfo = infos.get(position);
        avatar.setImageUrl(userInfo.getAvatar(), R.drawable.touxiang, R.drawable.touxiang);
        nickname.setText(userInfo.getNickname());
        signature.setText(userInfo.getSignature());

        return mView;
    }
}
